package WTE;

import java.util.Scanner;

public class Demo_03 {
    public static void main(String[] args) {

    }

    /**
     * 字符串中找出连续最长数字串
     */
    public static void method1() {
        Scanner sc = new Scanner(System.in);
        // 读入一个字符串
        String str = sc.nextLine();

        String strA = ""; // 用来记录最长的数字串
        String strB = ""; // 用来拼接数字串

        for (int i = 0; i < str.length(); i++) {
            char a = str.charAt(i);
            while (a > '0' && a < '9') {
                strB += a;
                if (i == str.length() - 1) {
                    break;
                }
                a = str.charAt(++i);
            }
            if (strB.length() > strA.length()) {
                strA = strB;
            }
            strB = "";
        }
        System.out.println(strA);
    }

    /**
     * 数组中出现次数超过一半的数字
     * 选票法: 抵消
     */
    public int MoreThanHalfNum_Solution (int[] numbers) {
        int votes = 0; // 票数
        int ans = 0; // 选票人

        for (int i = 0; i < numbers.length; i++) {
            if(votes == 0){
                ans = numbers[i];
                votes++;
            }else{
                if(numbers[i] == ans){
                    votes++;
                }else{
                    votes--;
                }
            }
        }
        return ans;
    }

}
